package ext;

import models.Ingredient.Unit;
import play.templates.JavaExtensions;

public class CountFormat extends JavaExtensions {
    public static String countFormat(Float number, Unit unit) {
        String count = null;
        if (number % 1 == 0) {
            count = String.valueOf(number.intValue());
            return count + " " + printUnit(number, unit);
        } else {
            if (unit == Unit.PCS && number == 0.5) {
                count = "половинка";
                return count;
            } else {
                count = String.valueOf(number);
                return count + " " + printUnit(number, unit);
            }
        }
    }

    private static String printUnit(Float number, Unit unit) {
        if (unit == Unit.GRAM) {
            return "г";
        } else if (unit == Unit.PCS) {
            return "шт.";
        } else if (unit == Unit.TABLESPOON) {
            return "ст.л.";
        } else if (unit == Unit.TEASPOON) {
            return "ч.л";
        } else if (unit == Unit.GLASS) {
            return number == 1 ? "стакан" : "стакана";
        }
        return "";
    }
}
